package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;
import java.util.List;

import javax.swing.AbstractAction;
import javax.swing.Action;

import com.mrogrape.notepad.activity.MainFrame;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.ClosableTabPanel;


public class CloseOthersMenuItemAction extends AbstractAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public CloseOthersMenuItemAction(){

		super.putValue(Action.NAME, "Close Others");
		super.putValue(Action.SHORT_DESCRIPTION, "Close Others tab.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		MainFrame frame = ViewContext.getMainFrame();
		ClosableTabPanel currentWorkPanel = frame.getCurrentWorkPanel();
		if(currentWorkPanel == null){
			return;
		}

		List<ClosableTabPanel> workPanelList = frame.getAllWorkPanels();
		for(ClosableTabPanel panel : workPanelList){

			if(panel != currentWorkPanel){

				frame.closeWorkPanel(panel);
			}
		}
	}
}
